#coding=utf-8
import codecs

__author__ = 'jy@cjlu.edu.cn'

#=======================================================================================================================
#功能编号:[0013]
#功能名称:内置参数管理
#功能:主要用于编辑和修改系统内置的参数信息
#=======================================================================================================================
from iLibP.loger import *
from basehandler import basehandler,checkpower
from config import *
from SysCommon.tools import *

fn="/CODES.py"
def Save(fn,text):
    """
    保存文件信息
    @param fn:
    @param text:
    @return:
    """
    try:
        f=open(TP_PATH+fn,"w")
        f.write(text)
        f.close()
        return True
    except :
        return False
def GetFile(fn):
    """
    获取文件信息，一致采用UTF8编码
    @param fn:
    @return:
    """
    text=codecs.open(TP_PATH+fn,"r","utf-8").read()
    return text

class List(basehandler):
    @checkpower("0013")
    def get(self):
        self.set_header("Content-Type", "text/html; charset=UTF-8")
        i=self.input()
        i.text=GetFile(fn)
        t=global_lookup.get_template("f00/T/f0013_list.html")
        self.write(t.render(i=i))

    @checkpower("0013")
    def post(self):
        """
        采用ajax方式处理
        @return:
        """
        self.set_header("Content-Type", "application/json; charset=UTF-8")
        i=self.input()
        if i.act=="save" and i.text:
            if Save(fn,i.text):
                self.write(toJson({"result":"OK"}))
            else:
                self.write(toJson({"result":"NOOK"}))